# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=chromaprint
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.0
pkgrel=1
pkgdesc="Library that implements a custom algorithm for extracting fingerprints from any audio source (mingw-w64)"
arch=('any')
url="https://acoustid.org/chromaprint"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip' 'staticlibs')
source=("https://github.com/acoustid/${_realname}/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('573a5400e635b3823fc2394cfa7a217fbb46e8e50ecebd4a61991451a8af766a')

prepare() {
  cd "${srcdir}"/${_realname}-v${pkgver}

}

build() {
  _common_opts=(
    -G"MSYS Makefiles"
    -DCMAKE_BUILD_TYPE=Release \
    -DFFT_LIB=kissfft \
    -DAUDIO_PROCESSOR_LIB="dummy" \
    -DBUILD_TESTS=off \
    -DBUILD_TOOLS=off \
  )

  msg "Build static version"
  [[ -d "${srcdir}/static-${MINGW_CHOST}" ]] && rm -r "${srcdir}/static-${MINGW_CHOST}"
  mkdir -p "${srcdir}/static-${MINGW_CHOST}" && cd "${srcdir}/static-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=off \
    "${_common_opts[@]}" \
    ../${_realname}-v${pkgver}

  make

  msg "Build shared version"
  [[ -d "${srcdir}/shared-${MINGW_CHOST}" ]] && rm -r "${srcdir}/shared-${MINGW_CHOST}"
  mkdir -p "${srcdir}/shared-${MINGW_CHOST}" && cd "${srcdir}/shared-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=on \
    "${_common_opts[@]}" \
    ../${_realname}-v${pkgver}

  make
}

package() {
  # static
  cd "${srcdir}/static-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install

  # shared
  cd "${srcdir}/shared-${MINGW_CHOST}"
  make DESTDIR=${pkgdir} install
}
